﻿Public Class TextStiles
    Public Shared Function NumbersOnly(ByVal pstrChar As Char, ByVal oTextBox As TextBox, Optional ByVal Entero As Boolean = True) As Boolean
        If Not Entero Then
            'validate the entry for a textbox limiting it to only numeric values and the decimal point
            If (Convert.ToString(pstrChar) = "." And InStr(oTextBox.Text, ".")) Then Return True 'accept only one instance of the decimal point
            If Convert.ToString(pstrChar) <> "." And pstrChar <> vbBack Then
                Return IIf(IsNumeric(pstrChar), False, True) 'check if numeric is returned
            End If
        Else
            If pstrChar <> vbBack Then Return IIf(IsNumeric(pstrChar), False, True) 'check if numeric is returned
        End If
        Return False 'for backspace
    End Function

    Public Function DCCalc(ByVal BancoSucursal As String, ByVal Cuenta As String) As String
        Dim suma As UShort = 0
        Dim x As Byte = 2
        Dim dc1 As UShort
        Dim dc2 As UShort
        Dim arreglo() As UShort = {1, 2, 4, 8, 5, 10, 9, 7, 3, 6}
        'Calcular el dc1
        For Each c As Char In BancoSucursal.ToCharArray
            suma += System.Convert.ToUInt16(c.ToString) * arreglo(x)
            x += 1
        Next
        'Console.Write(suma.ToString + vbCrLf)
        dc1 = 11 - (suma Mod 11)
        If dc1 = 10 Then dc1 = 1
        If dc1 = 11 Then dc1 = 0
        'Calcular el dc2
        x = 0
        suma = 0
        For Each c As Char In Cuenta.ToCharArray
            suma += System.Convert.ToUInt16(c.ToString) * arreglo(x)
            x += 1
        Next
        'Console.Write(suma.ToString + vbCrLf)
        dc2 = 11 - (suma Mod 11)
        If dc2 = 10 Then dc2 = 1
        If dc2 = 11 Then dc2 = 0
        DCCalc = dc1.ToString + dc2.ToString
        Return DCCalc
    End Function
End Class
